home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1999 July
/
Macworld (1999-07).dmg
/
Shareware World
/
Info
/
For Developers
/
Mops 3.4.sea
/
Mops source
/
Asm Source
/
toplevel
< prev
next >
Wrap
Text File
|
1995-07-05
|
4KB
|
190 lines
\ Assembler ReeseWarner 3/85
\ 02/28/86 GDC Fixed :MCODE
\ Feb 88 MRH Revised main control loop
\ Apr 88 MRH Ensure base is decimal for InitASM
0 -> dlevel
0 value endLen
0 value endAddr
: MOVEBACK
addr: topFile 3 charCount negate (lseek) drop ;
: INITP { #pass -- }
#pass -> pass
0 -> charCount
tiblen -> pos
0 -> linect
0 -> codePos
0 -> errflag
0 -> storedToken ;
\ Eliminates any blank lines
: KILLEOLS ( -- )
BEGIN
nextToken 4 =
NUNTIL ;
: DOMIDDLE
msg" top"
errflag
IF \ if error then
211 asmError \ abort
abort
ELSE \ else
moveBack \ set up pass 2
2 initP
THEN ;
false value ENDFLAG
: MORE?
endFlag
IF \ if end flag then
false \ get out of loop
ELSE \ else
\ KillEols \ get rid of blank lines
start: token \ get a token
EndAddr EndLen get: token s= not val" ENDflag F=Found"
THEN ; \ if end of asm code then exit
: HANDLE_OPCODE { mnemonic -- }
opFmt: [ mnemonic ] -> opFmt \ Default format for this opcode
mnemonic val" final mnemonic is"
dup 0= -> endFlag
IF
getFormat \ Replace opFmt with explicit format if any
pass 1 =
IF
length: [ mnemonic ]
\ dup . cr \ for debugging
++> codePos \ add length to codepos
ELSE
here -> keephere \ builds bit codes
build: [ mnemonic ]
here keephere - ++> codePos
THEN
THEN ;
: ENTERLABEL
token query: symtab
nilP <> IF 253 asmError THEN \ Error if already defined
['] var newObj: tempH
codePos 2* here + obj: tempH put: **
tempH token enter: symtab unlock: tempH ;
: HANDLE_LABEL
msg" It's a label!"
nextToken drop
pass 1 = IF enterLabel THEN ;
: HANDLE_REST { \ mnemonic opc_found? -- }
nextToken eol = ?EXIT \ Out if nothing else on line
EndAddr EndLen get: token s= val" ENDflag T=Found"
-> endFlag
endFlag ?EXIT \ Out if assembly finished
token query: codes -> opc_found?
opc_found?
IF
-> mnemonic
ELSE
252 asmError \ Undefined opcode
THEN
opc_found?
IF
mnemonic handle_opcode
THEN ;
\ Assemble instructions, main control loop
0 value SEC#
: ASM
false -> endFlag
BEGIN \ Loop over all input lines
endFlag
NWHILE
getline
0 -> storedToken
label_there?
IF
handle_label false -> label_there?
THEN
handle_rest
REPEAT
pass 1 =
IF
doMiddle
asm \ Recursive call
THEN ;
true value INITASM?
: InitASM
new: token ;
: EndASM
initAsm? 0EXIT
release: symTab release: token
true -> initAsm? ;
: WINDUP \ Winds up the assembly of one definition.
(Frefill) drop \ Gobble the ;code or ;mcode line
errflag IF 3 beep 3 beep abort THEN
(;) sec# ?defn ;
: (CODE)
initAsm? IF initASM THEN
1 initP
asm
windup ;
: TOCODE \ Exported. Switches to assembly within a definition.
" ;CODE" -> endLen -> endAddr
310 dup -> sec# \ Security check
(code) ; immediate
: :CODE \ Exported. Begins compilation of code word.
" ;CODE" -> endLen -> endAddr
310 dup -> sec# \ Security check
code \ Start a code definition
(code) ;
\ :MCODE - word exported to dictionary. Begins compilation of code method.
: :MCODE { \ selID -- }
true -> method?
?class 311 dup -> sec# \ Security check
" ;MCODE" -> endLen -> endAddr
getSelect -> selID
\ selID ^class 4 (findm) \ is method already defined?
\ IF
\ warnings?
\ IF
\ cr 0 -> out here count type
\ ." redefined as code"
\ THEN
\ ^class > ?error 183 \ if in same class, error
\ drop
\ THEN
selID m_header \ Build method header
(code) ;
" Operands" loadOps \ get operands in "operands"
" AsmCodes" loadcodes \ get opcode codes in AsmCodes
' endAsm setRelease